<?php


namespace App\Dao;

use App\Model\PaymentLog;

class PaymentLogDao extends AbstractDao
{
    public function where(array $where): \Hyperf\Database\Model\Builder
    {
        $query = PaymentLog::query();

        foreach ($where as $field => $value) {
            switch ($field) {
                default:
                    $query->where($field, $value);
                    break;
            }
        }

        return $query;
    }

    /**
     * 按条件检索数据
     * @param $where
     * @param array $page
     * @return \Hyperf\Contract\LengthAwarePaginatorInterface
     */
    public function getRechargeQuery($where,array $page)
    {
        if (isset($where['start_date']) && isset($where['end_date'])){
            $start_date = $where['start_date'];
            $end_date = $where['end_date'];
            unset($where['start_date']);
            unset($where['end_date']);
            return PaymentLog::query()
                ->where($where)
                ->whereBetween('created_at',[$start_date,$end_date])
                ->orderBy('id','DESC')
                ->paginate($page['per_page'],['*'],'page',$page['page']);
        }else{
            return $this->where($where)
                ->orderBy('id','DESC')
                ->paginate($page['per_page'],['*'],'page',$page['page']);
        }
    }
}